from pyecharts.charts import Bar
from pyecharts import options as opts

#结果是一个网页
#柱状图
bar=Bar()
bar.add_xaxis(['苹果','香蕉','梨子','桃子','草莓'])
bar.add_yaxis('商铺A',[178,83,71,18,63])
bar.add_yaxis('商铺B',[35,26,73,196,33])
bar.set_global_opts(title_opts=opts.TitleOpts(title='某商场水果销量'))
bar.render('pye柱.html')

#条形图
bar=Bar()
bar.add_xaxis(['苹果','香蕉','梨子','桃子','草莓'])
bar.add_yaxis('商铺A',[178,83,71,18,63])
bar.add_yaxis('商铺B',[35,26,73,196,33])
bar.set_global_opts(title_opts=opts.TitleOpts(title='某商场水果销量'))
bar.set_series_opts(label_opts=opts.LabelOpts(position='right')) #图形上的数字显示在右侧
bar.reversal_axis() # 行列互换
bar.render('pye条.html')

#饼图
from pyecharts.charts import Pie
c=Pie()
l1=['苹果','香蕉','梨子','桃子','草莓']
l2=[178,83,71,18,63]
c.add('',[list(z) for z in zip(l1,l2)]) # 转成嵌套列表结构
c.set_global_opts(title_opts=opts.TitleOpts(title='某商场水果销量'))
c.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))
c.render('pye饼.html')

#环状图
from pyecharts.charts import Pie
c=Pie()
c.add('',[list(z) for z in zip(l1,l2)],radius=['40%','75%']) # 转成嵌套列表结构
c.set_global_opts(title_opts=opts.TitleOpts(title='某商场水果销量'))
c.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))
c.render('pye环.html')

#玫瑰图
from pyecharts.charts import Pie
c=Pie()
c.add('',[list(z) for z in zip(l1,l2)],radius=['40%','55%'],rosetype='radius') # 转成嵌套列表结构
c.set_global_opts(title_opts=opts.TitleOpts(title='某商场水果销量'))
c.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))
c.render('pye玫瑰.html')

#漏斗图
from  pyecharts.charts import Funnel

f=Funnel()
f.add('',[list(z) for z in zip(l1,l2)])
f.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{c}'))
f.render('pye漏斗.html')

#散点图
from pyecharts.charts import Scatter
d1=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
d2=[298,614,631,464,86,342,486]
d3=[284,63,185,418,634,313,84]
s=Scatter()
s.add_xaxis(d1)
s.add_yaxis('商铺A',d2)
s.add_yaxis('商铺B',d3)
s.set_global_opts(title_opts=opts.TitleOpts(title='周销售额（万）'))
s.render('pye点.html')

#k线图
from pyecharts.charts import Kline

data=[[230,530,150,860],[530,440,430,660],[440,890,100,1100]]
days=[f'2025/4/{d}' for d in range(1,30)]
k=Kline()
k.add_xaxis(days)
k.add_yaxis('2025年4月K线',data)
k.render('pyeK.html')

#仪表盘
from pyecharts.charts import Gauge
g=Gauge()
g.add('作业进度',[('完成率',55.5)],
      axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=[(0.3,"#67e0e3"),(0.7,"#37a2da"),
                                                                               (1,"#fd666d")],width=30)))
g.set_global_opts(legend_opts=opts.LegendOpts(is_show=False))
g.render('pye表.html')

#词云
from pyecharts.charts import WordCloud
words=[("牛肉面",7800),("麦当劳",9000),("电视剧",3000),("石锅拌饭",100)]
w=WordCloud()
w.add('',words)
w.render('pye词.html')

#地图
from pyecharts.charts import Map
t=[23,25,26,31,27]
loc=['武汉市','十堰市','襄阳市','孝感市','荆州市']
m=Map()
m.add('',[list(z) for z in zip(loc,t)],"湖北")
m.set_global_opts(visualmap_opts=opts.VisualMapOpts())
m.render('pye地图.html')

#流动图
from pyecharts.charts import Geo
from pyecharts.globals import ChartType,SymbolType
c=(
    Geo()
    .add_schema("china")
    .add("",[("北京",80),("重庆",50),("上海",66),("深圳",71)],
         type_=ChartType.EFFECT_SCATTER,
         color="blue")
    .add("",[("北京","上海"),("北京","重庆"),("北京","深圳"),("深圳","重庆"),("上海","重庆"),("深圳","北京")],
         type_=ChartType.LINES,
         effect_opts=opts.EffectOpts(
             symbol=SymbolType.ARROW,
             symbol_size=6,
             color="red"
         ),
         linestyle_opts=opts.LineStyleOpts(curve=0.2))
    .set_global_opts(visualmap_opts=opts.VisualMapOpts())
)
c.render("pye流.html")